<?php

namespace App\Http\Controllers\Reception\Setting;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Cache;
use Illuminate\Http\Request;
// 设置模块
class WxSettingController extends Controller
{
    //获取文章微信小程序码
    public function getWxUnlimited(Request $request)
    {
        $token = $request->query('token');
        //验证权限
        $verifytoken = verifytokens($token);
        if (is_array($verifytoken)) {
            return $verifytoken;
        }
        $map['setting_id'] = 1;
        $info = DB::table('setting')->where($map)->first();
        $info->value = json_decode($info->value, true);
        $Appid = $info->value[0]['value'];
        $AppSecret = Crypt::decryptString($info->value[1]['value']);
        $token = getWeiXinAccessToken($Appid, $AppSecret);
        $scene = $request->query('scene');
        $page = $request->query('page');
        $url = getWeiXinUnlimited($scene, $page, $token);
        $url = http_type() . $_SERVER['HTTP_HOST'] . $url;
        if ($url) {
            $data = success();
            $data['data'] = $url;
        } else {
            $data = fail();
        }
        return $data;
    }
}
